<!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
      <title>修改支付密码</title>
      <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
      <script type="text/javascript" src="../../script/jquery-1.x.js"></script>
      <style>

          body{
            background-color: #fcfcfc;
            height:100%;
            padding-top:40px;
          }
          .header{
            width: 100%;height:40px;background: #f5f5f5;
          }
          .leftreturn{
            width:25px;
            height:25px;
            margin:7.5px;
            float: left;
          }

          ul li{
              list-style: none;
          }
          .elpw_tab{
              padding: 5px;
          }
          .elpw_tab li{
              padding: 5px; clear:both;
              height:40px;
          }
          .elpw_tab li label{
              width:30%;line-height:25px; display:block; float:left;
          }
          input{
              outline: none;

          }
          .elpw_input{
              border-bottom: 1px solid #ccc;
              width: 60%;
              outline: none;
          }
          .elpw_tab li:last-child{
          text-align: center;
          }
      </style>
  </head>
  <body>
    <div class="header">
      <img src="../../image/leftreturn.png" alt="" class="leftreturn" onclick="returnsz();">
    </div>
     <ul class="elpw_tab">
      <li><label>原密码：</label><input type="password" id="oldpassword" name="oldpassword" class="elpw_input" value=""></li>
      <li><label>新密码：</label><input type="password" id="password" name="password" class="elpw_input" value=""></li>
      <li><label>确认密码：</label><input type="password" id="password2" name="password2" class="elpw_input" value=""></li>
      <li><input value="完成" type="submit" onclick="doneSubmit()"> &nbsp&nbsp<input type="reset" value="重置" onclick="clear2()"></li>
    </ul>
  </body>
  <script type="text/javascript" src="../../script/api.js"></script>
  <script type="text/javascript" src="../../script/SHA1.js"></script>
  <script type="text/javascript">

  oldpassword = document.getElementById("oldpassword");
  password = document.getElementById("password");
  password2 = document.getElementById("password2");
  user = $api.getStorage('user');

      function returnsz() {
        api.closeWin();
      }

      //重置输入框
        function clear2(){
      document.getElementById('oldpassword').value='';
      document.getElementById('password').value='';
      document.getElementById('password2').value='';
        }

     //通过ajax修改密码
        function doneSubmit(){
          var boolean = true;
        if(oldpassword.value==''){
          alert('密码不能为空！');
          oldpassword.focus();
           boolean = false;
        }else if(password.value==''){
          alert('密码不能为空！');
          password.focus();
          boolean = false;
        }else if(password.value.length<6){
          alert('密码至少为6位，请重新输入！');
          password.focus();
          boolean = false;
        }else if(password.value!=password2.value) {
          alert('你两次输入的密码不一致，请重新输入！');
          password2.focus();
          boolean = false;
        }else if(oldpassword.value!=user[0].paypassword){
            alert('原密码不正确！');
            oldpassword.focus();
            boolean = false;
        }
        if(boolean == true){
          var now = Date.now();
           appKey = SHA1("A6032422409194"+"UZ"+"808CF36B-60D4-DC5D-C9F3-FB49F9E1FB44"+"UZ"+now)+"."+now

           api.ajax({
               url: 'https://d.apicloud.com/mcm/api/user/'+user[0].id,
               method: 'post',
               cache:false,
               headers: {
                   "X-APICloud-AppId": "A6032422409194",
                   "X-APICloud-AppKey": appKey
               },
               data: {
                   values: {
                       paypassword: password.value,
                       _method:'PUT'
                   }
               }
           },function(ret, err){
               if (ret) {
                   alert( '支付密码修改成功' );

                   api.openWin({
                       name: 'index',
                       url: '../../index.html',
                       pageParam: {
                           name: 'test'
                       }
                   });

               } else {
                   alert( '密码修改失败' );
               }
           });

        }
        }


  </script>
  </html>
